<?php

include_once('datos/TableEntityDAL.php');

$tableName = "usuario";

if(isset($_POST['tableName']))
{
	$tableName = $_POST['tableName'];
}
else
{
	if(isset($_GET['tableName']))
	{
		$tableName = $_GET['tableName'];
	}
}

$page = $_POST['page'];
$limit = $_POST['rows'];
$sidx = $_POST['sidx'];
$sord = $_POST['sord'];

if (!$sidx)
    $sidx = 1;

$entity = new TableEntityDAL($tableName);
$resultEntity = $entity->obtenerRegistros();
$cantFilas = $entity->cantidadFilas();

$count = $cantFilas;

if ($count > 0 && $limit > 0) {
    $total_pages = ceil($count / $limit);
} else {
    $total_pages = 0;
}

if ($page > $total_pages)
    $page = $total_pages;

$start = $limit * $page - $limit;

if ($start < 0)
    $start = 0;

$filter = "";
$xmlOut = $entity->obtenerRegistrosFormatoXml($filter, $tableName, $limit);

header("Content-type: text/xml;charset=utf-8");

echo $xmlOut;
?>

